//
//  CZCommentHeadView.swift
//  GZWeibo666
//
//  Created by  sr on 15/12/1.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

//按钮点击代理
protocol CZCommentHeadViewDelegate: NSObjectProtocol {
    func commentHeadViewButtonClick(headView: UIView)

}
class CZCommentHeadView: UIView {
    weak var delegate: CZCommentHeadViewDelegate?
    
    //微博模型
    var status: CZStatus? {
        didSet {
           setButton(commentButton, title: "评论", num: status!.comments_count)
           
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.grayColor()
        prepareUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func prepareUI() {
        //添加子控件
        addSubview(commentButton)
        //约束
        commentButton.ff_AlignInner(type: ff_AlignType.CenterLeft, referView: self, size: CGSize(width: 100, height: 44), offset: CGPoint(x: 10, y: 0))
    }
    
    func buttonDidClick() {
       print("评论数按钮被点击了")
    }
    
    func setButton(button: UIButton,title: String,num: Int) {
       let title = title + " " + "\(num)"
       button.setTitle(title, forState: UIControlState.Normal)
    }
    
   //懒加载
    private lazy var commentButton: UIButton = {
       let button = UIButton()
        button.setTitle("评论", forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(12)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Highlighted)
        button.addTarget(self, action: "buttonDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()
}
